﻿using System;

namespace DateRangeSlider
{
  public struct Tr
  {
    private readonly double _offset;
    private readonly double _scale;

    public Tr(double offset, double scale = 1)
    {
      _offset = offset;
      _scale = scale;
    }
    public Tr Invert()
    {
      return new Tr(-_offset / _scale, 1 / _scale);
    }
    public static Tr operator *(Tr x, Tr y)
    {
      return new Tr(y._offset + x._offset*y._scale, x._scale*y._scale);
    }

    public double Transform(double x)
    {
      return _offset + _scale * x;
    }
    public double TransformVector(double x)
    {
      return x*_scale;
    }

    public DateTime ToDate(double x)
    {
      return new DateTime((long)(_offset + _scale * x));
    }

    public DateTime Transform(DateTime x)
    {
      return new DateTime((long)(_offset + _scale * x.Ticks));
    }
    public TimeSpan TransformVector(TimeSpan x)
    {
      return TimeSpan.FromTicks((long)(_scale * x.Ticks));
    }
  }
}